// test.js
const blu=require('../../utils/blue.js');
const cmds = require('../../utils/cmd.js');
const app=getApp();
Page({
  blue_list:function(){
    var that=this;
      blu.blue_list(function(abc){
        that.setData({
          devices:abc
        });
      });
  }, 
  blue_close:function(){
    blu.blue_close();
  },
  blue_con:function(e){
     var deviceId=e.target.dataset.id;
     var that = this;      
     blu.blue_con(deviceId,function(){
        //设置连接值
         app.globalData.current_con_deviceId=deviceId;
         console.log("链接设备的---deviceId:" + deviceId);                               
      },function(str){
        //设置监听状态值
        var text=that.data.text+"\n"+str;
        that.setData({
          text: text,
        }); 
      });
  },
  
  blue_write:function(e){
    var sets='';
    if(e.currentTarget.id=='1'){
      sets = cmds.set4();//设置计步参数
    }else if(e.currentTarget.id=='2'){
      sets=cmds.set6_1();//开始心率
    }else if(e.currentTarget.id=='3'){
      sets = cmds.set6_2();//获取检测数据
    } else if (e.currentTarget.id == '4') {
      sets = cmds.set6_3();//关闭心率
    } else if (e.currentTarget.id == '5') {
      sets = cmds.set13_1();//开始震动
    } else if (e.currentTarget.id == '6') {
      sets = cmds.set13_2();//停止震动
    }else if(e.currentTarget.id=='7'){
      sets = cmds.set20();//设置时间
    } else if (e.currentTarget.id == '8') {
      sets = cmds.set3();//获取电量
    } else if (e.currentTarget.id == '9') {
      sets =cmds.set11();//恢复出厂设置
    }
    
    blu.blue_write(sets);
  },
  blue_read:function(){
    var charset_write = getApp().globalData.charset_write;  
    blu.blue_read(charset_write);
  },
  data: {
       text:"this is test\nthis is test",
       devices:'',     //设备列表       
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {            
    var hex_time = parseInt(new Date().getTime() / 1000).toString(16);   
    console.log(hex_time);
    console.log(hex_time.substr(6, 2));
    console.log(hex_time.substr(4, 2));
    console.log(hex_time.substr(2, 2));
    console.log(hex_time.substr(0, 2));
    //this.blue_list();    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})